<?php

class ItemList {
	private $itemList;

    function ItemList() {
    	$this->itemList = array();
    }
    
    /**
     * add - Add an item to the list
     */
    function add($item) {
    	$this->itemList[$item->id] = $item;
    }
    
    function getItem($id) {
    	return $this->itemList[$id];
    }
    
    function getItemList() {
    	return $this->itemList;
    }
    
    function getNumOfItems() {
    	return count($this->itemList);
    }
    
    /**
     * isEmpty - returns true if list is empty, 
     * false otherwise.
     */
    function isEmpty() {
    	return count($this->itemList) == 0;
    }
    
    /**
     * remove - remove given item from list
     */
    function remove($itemId) {
    	unset($this->itemList[$itemId]);
    }

    /**
     * getArray() returns an array of all items for storage
     * in session variable
     */
    function toArray() {
    	$array = array();
    	if(!$this->isEmpty()) {
	    	foreach($this->itemList as $id=>$item) {
	    		$array[$id] = $item->toArray();
	    	}
    	}
    	return $array;
    }
}
?>